package com.framework.controller.yhbcontroller;

import com.framework.entity.ter.TerTerminalInfo;
import com.framework.exception.util.RespResult;
import com.framework.service.yhbservice.YhbCusTerService;
import com.framework.service.yhbservice.YhbTerminalService;
import com.framework.yhbEntity.user.YhbCusTer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 功能描述: 终端信息控制器
 *
 * @author ck
 * @date 2018/9/11 15:12
 */
@RestController
@Api(value="终端信息模块",tags={"终端信息模块"})
@RequestMapping(value = "yhbTerminal")
public class YhbTerminalController {

	@Autowired
	private YhbTerminalService yhbTerminalService;

	@Autowired
	private YhbCusTerService yhbCusTerService;

	/**
	 * 查询商户的sn信息列表
	 * @param token
	 * @return
	 */
	@PostMapping("user/queryTerminalInfoList")
	@ApiOperation("获取终端信息列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name="token",value="登录产生的token",dataType="String", paramType = "query",required = true)
	})
	public RespResult queryTerminalInfoList(String token){
		Map<String,Object> map = yhbTerminalService.queryTerminalInfoList(token);
		return RespResult.ok(map);
	}

	/**
	 * 获取终端详情
	 * @param sn
	 * @return
	 */
	@GetMapping("getTerminalInfoBySn")
	@ApiOperation("获取终端详情")
	@ApiImplicitParams({
			@ApiImplicitParam(name="sn",value="终端sn",dataType="String", paramType = "query",required = true)
	})
	public RespResult getTerminalInfoBySn(String sn){
		TerTerminalInfo info =yhbTerminalService.queryTerminalInfoBySn(sn);
		return RespResult.ok().put("info",info);
	}

	/**
	 * 获取终端类别
	 * @param deptId
	 * @return
	 */
	@GetMapping("getTerminalModel")
	@ApiOperation("获取终端类别")
	@ApiImplicitParams({
			@ApiImplicitParam(name="deptId",value="渠道id",dataType="Long", paramType = "query",required = true)
	})
	public RespResult getTerminalModel(Long deptId){
		List<Map<String, Object>> list = yhbTerminalService.getTerminalExample(deptId);
		return RespResult.ok().put("list",list);
	}



    /**
     * 获取终端示例
     * @param sn
     * @return
     */
    @GetMapping("getCusTerminal")
    @ApiOperation("查看终端申请情况")
    @ApiImplicitParams({
            @ApiImplicitParam(name="sn",value="终端sn",dataType="integer", paramType = "query",required = true)
    })
    public RespResult getCusTerminal(String sn){
		Map<String,Object> info = yhbCusTerService.queryInfoBySn(sn);
        return RespResult.ok().put("customer",info);
    }


	/**
	 * 申请传统终端
	 * @param sn
	 * @return
	 */
	@PostMapping("applyCusTerminal")
	@ApiOperation("申请传统终端")
	@ApiImplicitParams({
			@ApiImplicitParam(name="sn",value="终端sn",dataType="integer", paramType = "query",required = true)
	})
	public RespResult applyCusTerminal(String username,String phone,String sn){
		YhbCusTer yhbCusTer = yhbCusTerService.applyCusTerminal(username,phone,sn);
		return RespResult.ok().put("customer",yhbCusTer);
	}


	/**
	 * 修改申请信息
	 * @param username
	 * @param phone
	 * @param sn
	 * @param yhbCusTerId
	 * @return
	 */
	@PostMapping("updateCusTerminal")
	@ApiOperation("修改终端申请")
	@ApiImplicitParams({
			@ApiImplicitParam(name="sn",value="终端sn",dataType="integer", paramType = "query",required = true),
			@ApiImplicitParam(name="username",value="终端sn",dataType="integer", paramType = "query",required = true),
			@ApiImplicitParam(name="terminalType",value="终端类型",dataType="integer", paramType = "query",required = true),
			@ApiImplicitParam(name="phone",value="手机号码",dataType="integer", paramType = "query",required = true),
			@ApiImplicitParam(name="yhbCusTerId",value="用户信息主键",dataType="integer", paramType = "query",required = true)
	})
	public RespResult updateCusTerminal(String username, String phone, String sn,String yhbCusTerId,Integer terminalType){
		YhbCusTer yhbCusTer = yhbCusTerService.updateCusTerminal(username,phone,sn,yhbCusTerId,terminalType);
		return RespResult.ok().put("customer",yhbCusTer);
	}


	/**
	 * 申请百易终端
	 * @param sn
	 * @return
	 */
	@PostMapping("user/applyBaiYiTerminal")
	@ApiOperation("申请百易终端")
	@ApiImplicitParams({
			@ApiImplicitParam(name="token",value="登录产生的token",dataType="String", paramType = "query",required = true),
			@ApiImplicitParam(name="sn",value="终端sn",dataType="String", paramType = "query",required = true)
	})
	public RespResult applyBaiYiTerminal(String token,String sn){
		yhbCusTerService.applyBaiYiTerminal(token,sn);
		return RespResult.ok();
	}
	/**
	 * 删除终端
	 * @param sn
	 * @return
	 */
	@GetMapping("user/deleteTerminal")
	@ApiOperation("删除终端")
	@ApiImplicitParams({
			@ApiImplicitParam(name="token",value="登录产生的token",dataType="String", paramType = "query",required = true),
			@ApiImplicitParam(name="sn",value="终端sn",dataType="String", paramType = "query",required = true)
	})
	public RespResult deleteTerminal(String token,String sn){
		yhbTerminalService.deleteTerminal(token,sn);
		return RespResult.ok();
	}

	/**
	 * 取消传统终端
	 * @param sn
	 * @return
	 */
	@GetMapping("cancelTerminal")
	@ApiOperation("取消传统终端")
	@ApiImplicitParams({
			@ApiImplicitParam(name="sn",value="终端sn",dataType="String", paramType = "query",required = true)
	})
	public RespResult cancelTerminal(String sn){
		yhbCusTerService.cancelTerminal(sn);
		return RespResult.ok();
	}


}
